/**************************************************************************(C)*
 *
 *  This file is part of the GreenHills project
 *  Copyright (C) 2009  Tieto Corporation
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  Not for commmercial use. Only with Tieto permission.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *************************************************************************(C)*/

#pragma once

#include "iroomitem.h"
#include "iroom.h"
#include "coredll.h"

namespace greenhills {
namespace core {

typedef unsigned int CClientId;

class IServerListener;

/** @brief Greenhills server interface decaration
 *
 * Provides abstract methods for communication of connected clients with
 * a server.
 */
class GH_CORE_CLASS IServer
{
public:
    virtual ~IServer() {}

public:
    virtual CClientId login(const std::string &pUsername,
                       const std::string &pPassword) = 0;
    virtual bool logout(const core::CClientId &pClientId) = 0;

    virtual CRoomId createRoom(const core::CClientId &pClientId,
                               const std::string &pRoomName,
                               const CRoomType &pRoomType,
                               const std::string &pPassword) = 0;
    virtual bool joinRoom(const core::CClientId &pClientId,
                          const CRoomId &pRoomId,
                          const std::string &pPassword) = 0;
    virtual bool leaveRoom(const core::CClientId &pClientId,
                           const CRoomId &pRoomId) = 0;

    virtual CItemId addItem(const core::CClientId &pClientId,
                            const CRoomId &pRoomId,
                            const std::string &pItemName,
                            const CItemType &pItemType) = 0;
    virtual bool removeItem(const core::CClientId &pClientId,
                            const CRoomId &pRoomId,
                            const CItemId &pItemId) = 0;
    virtual bool updateItem(const core::CClientId &pClientId,
                            const CRoomId &pRoomId,
                            const CItemId &pItemId,
                            const unsigned char *pData,
                            unsigned int pLength) = 0;

public: //listeners management
    virtual void registerListener(core::IServerListener *listener) = 0;
    virtual void unregisterListener(core::IServerListener *listener) = 0;
    virtual void unregisterAllListeners() = 0;
};

/** @brief Interface decaration for server listeners
 *
 * This interface is used for sending notifications to all objects interested in
 * certain server object.
 */
class GH_CORE_CLASS IServerListener
{
public:
    virtual void itemAdded(const core::CRoomId &pRoomId,
                           const core::CItemId &pItemId,
                           const std::string &pItemName,
                           const core::CItemType &pItemType) = 0;
    virtual void itemUpdated(const core::CRoomId &pRoomId,
                             const core::CItemId &pItemId,
                             const unsigned char *pData,
                             unsigned int pLength) = 0;
    virtual void itemRemoved(const core::CRoomId &pRoomId,
                             const core::CItemId &pItemId) = 0;
};

} //namespace core
} //namespace greenhills
